package com.xs.ahoi.hcxs.adapter;

import android.content.Context;
import android.widget.SimpleAdapter;
import com.xs.ahoi.hcxs.utils.ObjectUtils;

import java.util.List;
import java.util.stream.Collectors;

public class MySimpleAdapter<T> extends SimpleAdapter {

    private List<T> datas;

    public MySimpleAdapter(Context context, List<T> datas, int resource, String[] from, int[] to) {
        super(context, datas.stream().map(ObjectUtils::obj2Map).collect(Collectors.toList()), resource, from, to);
        this.datas = datas;
    }

    public MySimpleAdapter(Context context, List<T> datas, int resource) {
        super(context, datas.stream().map(ObjectUtils::obj2Map).collect(Collectors.toList()), resource, new String[]{}, new int[]{});
        this.datas = datas;
    }

    @Override
    public T getItem(int position) {
        return datas.get(position);
    }

    public void refresh(List<T> datas){
        this.datas = datas;
        notifyDataSetChanged();
    }

}
